﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinAutomator.Library.InOut;
using WinAutomator.Library.MainType;

namespace WinAutomator.Library.BuildIns
{
    public class WAReadDirectory : IProcess
    {
        public String WADirectory { get; set; }

        List<string> _result = null;
        List<VirtualConnector> _vconnector = new List<VirtualConnector>();

        public WAReadDirectory()
        {
            Out = new Connector<List<String>>(WAInOut.Out, this);
            Out.GetProcessData = getResult;

            VirtualConnector vOut = new VirtualConnector(WAInOut.Out);
            vOut.AddConnector(Out);
            _vconnector.Add(vOut);
        }

        public IConnector Execute()
        {
            string[] filePaths = Directory.GetFiles(WADirectory);
            _result = new List<string>();
            _result = filePaths.ToList<string>();

            return (IConnector)Out;
        }

        public List<string> getResult()
        {
            return _result;
        }

        public List<Type> getAcceptedType()
        {
            List<Type> type = new List<Type>() {typeof(object)};
            
            return type;
        }

        public List<VirtualConnector> getVirtualConnectors()
        {
            return _vconnector;
        }

        public List<VirtualConnector> getVirtualConnectors(WAInOut type)
        {
            List<VirtualConnector> tmp = new List<VirtualConnector>();

            foreach (VirtualConnector v in _vconnector)
                if (v.VirtualConnectorType == type)
                    tmp.Add(v);

            return tmp;
        }

        public Connector<List<String>> Out { get; set; }

    }
}
